<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>前端小蜗</title>
</head>
<body>

<p id="demo"></p>
<script>
    // JSON.stringify(value,replace,space)接收3个参数
    // 1.value 目标对象 
    // 2.replace Array || Function   文本添加缩进、空格和换行符
    // 3.space Number|| String 文本添加缩进、空格和换行符
var str = {"name":"前端", "site":"https://gitee.com/xiaowotie/web_xiaowo"}
str_pretty1 = JSON.stringify(str)
document.write( "只有一个参数情况：" );
document.write( "<br>" );
document.write("<pre>" + str_pretty1 + "</pre>" );
document.write( "<br>" );

str_pretty2 = JSON.stringify(str, ['name']) 
str_pretty2 = JSON.stringify(str, (key, value)=>{
	if(key === 'name'){
	return '前端小蜗'
	}
	return value;
}) 
document.write( "传入replace参数情况：" );
document.write( "<br>" );
document.write("<pre>" + str_pretty2 + "</pre>" ); // pre 用于格式化输出

str_pretty2 = JSON.stringify(str, (key, value)=>{
	if(key === 'name'){
	return '前端小蜗'
	}
	return value;
},4) //使用四个空格缩进

document.write( "传入replace,space参数情况：" );
document.write( "<br>" );
document.write("<pre>" + str_pretty2 + "</pre>" ); // pre 用于格式化输出
</script>

</body>
</html>